package dto

import (
	"algo-sdk-go/project/matchmaking/domain/models/entity"
	"algo-sdk-go/project/matchmaking/domain/port/repo/ops"
)

var (
	LoadUserAllInfoUserNum = func(u UserAllInfo) int { return u.UserNum }
)

type UserAllInfo struct {
	UserNum    int // 用户编号
	MatchScore int // 匹配的分数

	UserProfile    entity.UserProfile
	MatePreference entity.MatePreference
}

func AssembleUserAllInfo(userProfile entity.UserProfile, matePreference entity.MatePreference) UserAllInfo {
	return UserAllInfo{
		UserNum:        userProfile.UserNum,
		MatchScore:     0,
		UserProfile:    userProfile,
		MatePreference: matePreference,
	}
}

func (u *UserAllInfo) GetUserProfileCommand() ops.Condition {
	cmd := ops.Condition{
		UserNumList: nil,
		Gender:      u.UserProfile.Gender.Negation().Value(),

		AgeRange:       u.MatePreference.AgeRange,
		HeightRange:    u.MatePreference.HeightRange,
		WeightRange:    u.MatePreference.WeightRange,
		EducationRange: u.MatePreference.EducationRange,
		IncomeRange:    u.MatePreference.IncomeRange,

		Occupation:                 "",
		HometownPreference:         u.MatePreference.HometownPreference,
		CurrentResidencePreference: u.MatePreference.CurrentResidencePreference,
		ParentsHasPension:          false,
		PageNum:                    0,
		PageSize:                   0,
		IgnorePage:                 false,
		SortBy:                     nil,
		WithStatus:                 false,
		WithDelete:                 false,
	}
	return cmd
}

type MatchWeight struct {
}

func (u *UserAllInfo) Match(b UserAllInfo) bool {
	return true
}

type UserAllInfoList []UserAllInfo

func (a UserAllInfoList) Len() int           { return len(a) }
func (a UserAllInfoList) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a UserAllInfoList) Less(i, j int) bool { return a[i].MatchScore < (a[j].MatchScore) }
